import axios from 'axios'
import { localGet } from '../utils'

// axios.create 创建一个公共配置，create可以创建多个不同接口的公共配置
const http = axios.create({
  baseURL:'http://backend-api-02.newbee.ltd/manage-api/v1/',
  timeout:6000,
  headers: {
    ["Content-Type"]: "application/json;charset=UTF-8"
  }
})
//添加token
http.defaults.headers['token'] = localGet('token') || ''
// 请求拦截器
http.interceptors.request.use(config => {
  return config;
},error => {
  // 错误请求处理
  return Promise.reject(error)
})

// 响应拦截器
http.interceptors.response.use(response => {
  return response.data;
},error => {
  return Promise.reject(error)
})

export default http